<template>
  <div class="addlink">
    <hunk-head customEvent="true" @headFn="gobanck" name="室友邀请链接"></hunk-head>
    <div class="link-info">
      <div class="one">{{info.unickname}}邀请您入住</div>
      <div class="address">{{info.outtype ? '整租':'合租'}}-{{info.address}}</div>
      <div class="queren">请确认您的身份信息：</div>
      <div class="name">
        <div class="nai">姓名：</div>
        <div>{{info.roommatename}}</div>
      </div>
      <div class="name">
        <div class="nai">身份证号：</div>
        <div>{{info.roommatecardid}}</div>
      </div>
    </div>
    <div class="link-btn">
      <div class="quxiao" @click="cancel">取消</div>
      <div class="queren" @click="addRoomy">确认</div>
    </div>
    <uni-popup ref="popup1" type="center">
      <div class="tips1">
        <div class="tips-top">认证授权</div>
        <div class="tips-text">尊敬的用户，您还未进行实名认证，是否进行实名认证</div>
        <div class="tips-btn">
          <div class="btn-closs" @click="closePopup1">取消</div>
          <div  @click="gorenzheng">确认</div>
        </div>
      </div>
    </uni-popup>
    <uni-popup ref="approve" type="center">
      <div class="tips2">
        <div class="tips-top">提示</div>
        <div class="tips-text">尊敬的用户，您还未进行用户授权，是否进行用户授权？</div>
        <div class="tips-btn">
          <div class="btn-closs" @click="closeP">取消</div>
          <div  @click="checkedP">确认</div>
        </div>
      </div>
    </uni-popup>
  </div>
</template>

<script>
import Head from '@componentsMine/head'
import { isaggre, showinfo } from '@/apis/tenant/roomy'
import store from '@store/index'
import {GetUserInfo_openid,getuseropenid} from '@/apis/user'
import { setToken } from '@utils/auth'
export default {
  components: {
    'hunk-head': Head
  },
  data() {
    return {
      info: null,
      wid:''
    }
  },
  onLoad(e){
    let data = JSON.parse(e.query)
    this.wid = data.wid
    console.log('this.info',this.info)
    this.showinfo(data.wid)
    // this.$forceUpdate()
    this.isShouquan()
  },
  computed: {
    userInfo(){
      return this.$store.state.baseStore.userInfo
    }
  },
  methods: {
    checkedP(){
      this.$refs.approve.close()
      uni.navigateTo({ url: '/subPackage/link/approve' })
    },
    closeP(){
      this.$refs.approve.close()
      uni.reLaunch({ url: '/pages/login/checkUser' })
    },
    showinfo(wid){
      let that = this
      showinfo({wid:wid}).then(res=>{
        if(res.code == 200){
          that.info = res.data
        }else{
          uni.showToast({
            title: res.msg,
            icon: 'none'
          })
        }
      })
    },
    gobanck(){
      uni.redirectTo({ url: '/pages/index/index' })
    },
    closePopup1(){
      this.$refs.popup1.close()
    },
    gorenzheng(){
      this.$refs.popup1.close()
      uni.navigateTo({ url: '/subPackage/link/renzheng' })
      // this.$jump({path:'/pages/link/renzheng'})
    },
    addRoomy(){
      let user = this.$store.state.baseStore.userInfo
      if(!user.userid){
        this.$refs.approve.open()
        return
      }
      const data = {
        "userid": user.userid,
        "wid": this.wid
      }
      // const data = {
      //   "userid": 6912,
      //   "wid": 40
      // }
      isaggre(data).then((res)=>{
        if(res.code == 200){
          uni.showToast({
            title: '添加成功',
            icon: 'none',
            success: ()=>{
              uni.redirectTo({ url: '/pages/index/index' })
            }
          })
        }else{
           uni.showToast({
            title: res.msg,
            icon: 'none'
          })
        }
      })
    },
    isShouquan(){
      let that = this
      wx.login({
        success:(res)=> {
          var code = res.code
          getuseropenid({code}).then(e=>{
            // if(e.data.openid != 'null'){
              wx.setStorageSync('openid', e.data.openid)
              wx.setStorageSync('session_key', e.data.session_key)
              GetUserInfo_openid({openid:e.data.openid}).then(e=>{
                console.log('执行GetUserInfo_openid',e)
                if(e.code == 200){
                  wx.setStorageSync('cardid', e.data.cardid)
                  store.commit('baseStore/SET_USERINFO', e.data)
                  setToken(e.data.token)
                }
              }).catch(e=>{
                
              })
            // }else{
            //   that.isCode = false
            //   that.$refs.wxpopup.open()
            // }
          })
        }
      })
    },
    cancel(){
      // this.$jump({ path: '/pages/tenant/roomy/addroomy'})
      uni.showToast({
        title: '取消成功',
        icon: 'none',
        success:()=>{
          uni.redirectTo({ url: '/pages/index/index' })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.addlink {
  width: 100vw;
  box-sizing: border-box;
  height: 100vh;
  background: #F9F9F9;
  .link-info{
    background: #fff;
    padding: 10px 15px 20px 15px;
    .one{
      text-align: center;
      font-size: 22px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #9B9B9B;
      line-height: 30px;
    }
    .address{
      text-align: center;
      margin: 10px 0 20px 0;
      font-size: 22px;
      font-family: PingFangSC-Semibold, PingFang SC;
      font-weight: 600;
      color: #000000;
      line-height: 30px;
    }
    .queren{
      text-align: center;
      font-size: 16px;
      font-family: PingFangSC-Semibold, PingFang SC;
      font-weight: 600;
      color: #000000;
      line-height: 22px;
    }
    .name{
      margin-top: 10px;
      display: flex;
      margin-left: 50px;
      text-align: left;
      font-size: 15px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #000000;
      line-height: 21px;
      .nai{
        color: #9B9B9B;
      }
    }
  }
  .link-btn{
    margin-top: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 16px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    line-height: 45px;
    text-align: center;
    .quxiao{
      width: 167px;
      height: 45px;
      border-radius: 100px;
      border: 1px solid;
      margin-right: 10px;
      color: #FFAA58;
    }
    .queren{
      width: 167px;
      height: 45px;
      background: linear-gradient(315deg, #FFAA58 0%, #FFBD6C 100%);
      box-shadow: 0px 2px 4px 0px rgba(252, 174, 55, 0.21), 0px 3px 5px 0px rgba(255, 216, 111, 0.14);
      border-radius: 100px;
      color: #FFFFFF;
    }
  }
  .tips1{
    width: 335px;
    height: 174px;
    display: flex;
    flex-direction: column;
    align-items: center;
    border-radius: 10px;
    background-color: #fff;
    position: relative;
    .tips-top{
      height: 22px;
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #4A4A4A;
      line-height: 22px;
      margin-top: 20px;
    }
    .tips-text{
      margin: 20px 0;
      height: 22px;
      font-size: 16px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #6D7278;
      line-height: 22px;
      padding: 0 20px;
      text-align: center;
    }
    .tips-btn{
      width: 100%;
      border-top: 2px solid #EFEFEF;
      display: flex;
      position: absolute;
      bottom: 0;
      div{
        height: 40px;
        width: 50%;
        font-size: 13px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #4A4A4A;
        line-height: 40px;
        text-align: center;
      }
      .btn-closs{
        border-right: 2px solid #EFEFEF;
      }
    }
  }
  .tips2{
    width: 335px;
    height: 174px;
    display: flex;
    flex-direction: column;
    align-items: center;
    border-radius: 10px;
    background-color: #fff;
    position: relative;
    .tips-top{
      height: 22px;
      font-size: 16px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #4A4A4A;
      line-height: 22px;
      margin: 20px 0 30px 0;
    }
    .tips-text{
      height: 22px;
      font-size: 16px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #6D7278;
      line-height: 22px;
      padding: 0 20px;
    }
    .tips-btn{
      width: 100%;
      border-top: 2px solid #EFEFEF;
      display: flex;
      position: absolute;
      bottom: 0;
      div{
        height: 40px;
        width: 50%;
        font-size: 13px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #4A4A4A;
        line-height: 40px;
        text-align: center;
      }
      .btn-closs{
        border-right: 2px solid #EFEFEF;
      }
    }
  }
}
</style>
